package com.personalforumapi.controller;

import com.personalforumapi.entity.comment;
import com.personalforumapi.repository.commentRepostitory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:kinjaze
 * @Date:2020/9/24 10:54
 */
@RestController
@RequestMapping("/comment")
public class commentController {
    @Autowired
    private commentRepostitory commentRepostitory;

    @GetMapping("/findByAid/{aid}")
    public List<comment> findByAid(@PathVariable("aid") Integer aid){
        return commentRepostitory.findByAid(aid);
    }

    @PostMapping("add")
    public boolean add(@RequestBody comment comment){
        if(commentRepostitory.save(comment).equals(comment)){
            return true;
        }else{
            return false;
        }
    }
    @PostMapping("update/{aid}")
    public void update(@PathVariable("aid") Integer aid,@RequestBody List<comment> comments){
        for(comment k : comments){
            commentRepostitory.updateByAid(aid,k.cagree,k.cid);
        }

    }
}
